 
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

typedef long long ll;
struct Edge {
    int v, nt;
    ll w;
} e[1000];

int h[15], cnt = 0;
ll ans = 1e18, sum = 0;
bool vis[15];
int n, m;  // 需要声明n和m

void add(int u, int v, ll w) {
    e[cnt] = {v, h[u], w};
    h[u] = cnt++;
}

void dfs(int u, ll val) {
    if (u == n) {
        ans = min(ans, val);
        return;
    }
    
    for (int i = h[u]; ~i; i = e[i].nt) {
        int v = e[i].v;
        ll w = e[i].w;  // 修正语法错误
        if (!vis[v]) {
            vis[v] = true;
            dfs(v, val ^ w);
            vis[v] = false;
        }
    }
}

int main() {
    memset(h, -1, sizeof h);
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int u, v;
        ll w;
        cin >> u >> v >> w;
        add(u, v, w);
        add(v, u, w);
    }
    
    vis[1] = true;
    dfs(1, 0);
    cout << ans << endl;
    return 0;
}
 